package _18_剑指OfferII;

public class _005_剑指OfferII单词长度的最大乘积 {

    public int maxProduct(String[] words) {
        int len = words.length;

        int[] toBits = new int[len];

        for (int i = 0; i < len; i++) {
            // 将字母装换为二进制数
            for (int j = 0; j < words[i].length(); j++) {
                toBits[i] |= 1 << (words[i].charAt(j) - 'a');
            }
        }

        int max = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i + 1; j < len; j++) {
                if ((toBits[i] & toBits[j]) == 0) {
                    max = Math.max(words[i].length() * words[j].length(), max);
                }
            }
        }
        return max;
    }

}
